/**
 * 根据 blob 下载文件
 *
 * @param blob_array
 * @param fileName 文件名
 */
export const downloadFile = (blob_array: any, fileName: any) => {
    //console.log(fileName);
    let blob = new Blob([blob_array], {type: "application/force-download"});
    // window.location.href = URL.createObjectURL(blob);
    let labelA = document.createElement('a');
    labelA.href = window.URL.createObjectURL(blob);
    labelA.download = fileName;
    labelA.click();
};

export const convertBase64ToBlob = (b64Data: any) => {
    let sliceSize = 512;
    let byteCharacters = atob(b64Data.substring(b64Data.indexOf(',') + 1));
    let byteArrays = [];
    for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
        let slice = byteCharacters.slice(offset, offset + sliceSize);
        let byteNumbers = new Array(slice.length);
        for (let i = 0; i < slice.length; i++) {
            byteNumbers[i] = slice.charCodeAt(i);
        }
        let byteArray = new Uint8Array(byteNumbers);
        byteArrays.push(byteArray);
    }
    return new Blob(byteArrays);
};
